package CustomUI;

import org.Consts;

import com.ydev.graphics.animations.R;

import GameTools.ydPoint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class ydImageCell extends FrameLayout {

	private Context mContext;
	private LayoutInflater layoutInflater;

	LinearLayout llMain;
	ImageView imgPicture;
	View bar;
	ImageView imgcheck;

	ydOnClickListeners listeners = new ydOnClickListeners();
	ydOnClickLongListeners longListeners = new ydOnClickLongListeners();

	boolean selected = false;

	public ydImageCell(Context context) {
		super(context);
		this.mContext = context;
		inflate();
		bindViews();
		init();
	}

	private void inflate() {
		layoutInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		layoutInflater.inflate(R.layout.gallery_cell, this, true);
	}

	private void bindViews() {
		llMain = (LinearLayout) findViewById(R.id.llMain);
		imgPicture = (ImageView) findViewById(R.id.imgSmallPicture);
		bar = (View) findViewById(R.id.view1);
		imgcheck = (ImageView) findViewById(R.id.imgCheckbox);
	}

	public void init() {
		this.setOnClickListener(listeners);
		this.setOnLongClickListener(longListeners);

		listeners.addOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				/*if (selected == true)
					setCellSelected(false);
				else
					setCellSelected(true);*/

			}

		});
	}

	public void setCellSelected(boolean b) {
		if (b) {
			imgcheck.setVisibility(View.VISIBLE);
			selected = b;
		} else {
			imgcheck.setVisibility(View.GONE);
			selected = b;
		}
	}

	public void setImage(Bitmap img) {

		imgPicture.setImageBitmap(img);
	}

	public void addOnClickListener(OnClickListener onClickListener) {
		listeners.addOnClickListener(onClickListener);

	}

	public void setSize(int x, int y) {
		android.view.ViewGroup.LayoutParams par = llMain.getLayoutParams();// =
																			// new
		// LinearLayout.LayoutParams(
		if (par == null)
			par = new LayoutParams(x, y);
		par.width = x;
		par.height = y;
		llMain.setLayoutParams(par);
		// 50, 50);
		// par.setMargins(10, 0, 0, 10);
	}

	public void addToLeftMargin(int i) {
		LayoutParams par = (LayoutParams) llMain.getLayoutParams();
		par.leftMargin+=i*5;
		llMain.setLayoutParams(par);

	}

	public void setBarColor(int layer) {
		bar.setVisibility(View.VISIBLE);
		bar.setBackgroundColor(Color.parseColor(Consts.colorsList[layer%Consts.colorsList.length]));
		
	}
}
